// components/loginDialog/loginDialog.js
const httpUtils = require('../../utils/httpUtils.js');
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    id: null,
    type: null,
    maskflag: null,
    loginflag: null,
    userflag: null
  },

  /**
   * 组件的初始数据
   */
  data: {
    useragreement: null,
    loginflag: true, //登录对话框
    userflag: true, //用户协议对话框
    maskflag: true, //阴影层
    isAgress: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    logincancal: function () {

      this.setData({
        maskflag: true,
        userflag: true,
        loginflag: true,

      })
      if (this.properties.type == 0) {
        wx.switchTab({
          url: '/pages/index/index',
        })
      }

    },
    loginsure: function () {
      //登录弹框确定
      this.setData({
        loginflag: true,
        userflag: false
      })
      this.getuseragreement();
    },
    getuseragreement: function () {
      let that = this
      wx.showLoading({
        title: '正在加载',
        mask: true
      })
      httpUtils.useragreement({
        access_token: app.globalData.$TOKEN
      }).then((res) => {
        wx.hideLoading()
        that.setData({
          useragreement: res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block"'),
          loginflag: true,
          userflag: false
        })
      });

    },
    usercancal: function () {
      //用户协议取消
      this.setData({
        userflag: true,
        maskflag: true,
      })
      if (this.properties.type == 0) {
        wx.switchTab({
          url: '/pages/index/index',
        })
      }
    },
    usersure: function () {
      this.setData({
        userflag: true,
        maskflag: true,
      })
      //同意用户协议 去登录
      wx.navigateTo({
        url: '/pages/login/login?id=' + this.data.id + "&type=" + this.data.type,
      })

    },
    scrollHandle: function () {
      console.log("scrollHandle");
      this.setData({
        isAgress: 1
      })
    },
  }
})